<template>
  <div style="background: #fff">
    <div class="title">
      <div>{{ title }}</div>
    </div>
     <div style="text-align:right">
      <el-form :inline="true">
        <el-form-item>
          <el-button type="primary" @click="showEdit(false)">添加</el-button>
        </el-form-item>
      </el-form>
    </div>
    <el-table
      :data="data"
      stripe
      style="width: 100%; margin-bottom: 1.875rem"
    
    >
      </el-table-column>
      <el-table-column prop="id" label="id"></el-table-column>
      <el-table-column prop="name" label="标题"></el-table-column>
       <el-table-column label="图片" >
          <template slot-scope="scope">
            <el-image
              :src="
                cdn+scope.row.cover +
                '?imageView2/1/w/50/h/50/format/webp/q/75|imageslim'
              "
              style="width:50px;height:50px"
              :preview-src-list="[cdn+scope.row.cover]"
            >
            </el-image>
          </template>
        </el-table-column>
         <el-table-column prop="sort" label="排序(数字越大越靠前)"></el-table-column>
       <el-table-column label="操作">
        <template slot-scope="scope">
              <el-button size="small" @click="showEdit(scope.row)">编辑</el-button>
          <el-button size="small" @click="del(scope.row)">删除</el-button>
        </template>
      </el-table-column>
     
    </el-table>


    <el-dialog title="编辑" :visible.sync="editModal" width="40%" :close-on-click-modal='false'>
        <el-form :model="item">
          <el-form-item label="标题">
            <el-input v-model="item.name" autocomplete="off" clearable></el-input>
          </el-form-item>
           <el-form-item label="排序">
            <el-input v-model="item.sort" autocomplete="off" clearable></el-input>
          </el-form-item>
           <el-form-item label="图片">
          <div style="display: flex">
            <div
              class="demo-upload-list"
              v-for="(item, index) in [item.cover]"
              :key="index"
             
            >
              <template  >
                <img
                  :src="
                    cdn +
                    item +
                    '?imageView2/1/w/100/h/100/format/webp/q/75|imageslim'
                  "
                />
                <div class="demo-upload-list-cover">
                  <i
                    class="el-icon-view icon"
                    @click="preview(item, index, false)"
                  ></i>
                </div>
              </template>
            </div>

            <el-upload
              class="avatar-uploader"
              action="http://upload.qiniup.com"
              :show-file-list="false"
              :on-success="uploadCover"
              :data="qnToken"
            >
              <i class="el-icon-plus avatar-uploader-icon"></i>
            </el-upload>
          </div>
        
        </el-form-item>
            <el-form-item label="内容">
            <el-input v-model="item.content" autocomplete="off" clearable type="textarea"></el-input>
          </el-form-item>
        </el-form>
        <div slot="footer" class="dialog-footer">
          <el-button @click="editModal = false">取 消</el-button>
          <el-button type="primary" @click="edit">确 定</el-button>
        </div>
      </el-dialog>
      <el-dialog title="预览" :visible.sync="previewModal" center>
      <!-- <img :src="cdn+img" alt=""> -->
      <el-image :src="cdn + img" lazy></el-image>
      <el-button
        v-if="showFoot"
        type="primary"
        @click="setImgIndex(previewIndex)"
        >设为首图</el-button
      >
    </el-dialog>
  
  </div>
</template>

<script>
import mixin from "../../js/mixin";

export default {
  name: "good",
  mixins: [mixin],
  data() {
    return {
      is_page: false,
      api_url: "shop/activity",
      query: {},
      item:{
          cover:''
      }
    };
  },
  components: {},
  mounted() {},
  created() {
    this.title = this.$route.meta.title
    this.init();
  },
  methods: {
    init() {
      this.getQnToken()
      this.getData()
    },

    showEdit(e) {
      if (e) {
        this.item = e;
      }else{
          this.item={
              cover:''
          }
      }
      this.editModal = true;
    },
  },
};
</script>

<style scoped>
</style>
